const parseRTF = require('rtf-parser')
const fs = require('fs')

//https://www.npmjs.com/package/rtf-parser
//https://github.com/iarna/rtf-parser  代码地址

// https://www.npmjs.com/package/@iarna/rtf-to-html
//https://www.npmjs.com/package/rtf2md
//C:\Users\xue\Desktop\dashboard-rtf-file\rtf\node_modules\rtf2md

const rtfFile ='2.rtf'

// ----------------------------------------------------------

parseRTF.stream(fs.createReadStream(rtfFile), (err, doc) => {
  console.log('-----------------------------------to rtf')
  console.log(JSON.stringify(doc.content,null,4))
  // console.log(doc.content)
})


// ----------------------------------------------------------

const rtfToHTML = require('@iarna/rtf-to-html')
rtfToHTML.fromStream(fs.createReadStream(rtfFile), (err, html) => {
  console.log('-----------------------------------to html')
  console.log(html)
})



// ----------------------------------------------------------

const rtf2md = require('rtf2md')
const util = require("util");

const readFile = util.promisify(fs.readFile);
const mdast2md = require("mdast-util-to-markdown");
readFile(rtfFile, "utf-8")
  .then(rtf2md)
  .then(mdast2md)
  .then((content)=>{
	  console.log('-----------------------------------to markdown')
	  console.log(content)
  });
